﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
using System.Globalization;

namespace SPIconIntegration.Code.Extensions
{
    /// <summary>
    /// Represents all extension methods used within this project
    /// </summary>
    [CLSCompliant(false)]
    public static class ExtensionMethods
    {
        /// <summary>
        /// Gets the jobdefintions by name.
        /// </summary>
        /// <param name="webApp">The webapplication.</param>
        /// <param name="name">The name.</param>
        /// <returns>SPJobDefinition</returns>
        /// <exception cref="System.ArgumentNullException">Exception is thrown when the service or name equal null</exception>
        public static SPJobDefinition GetJobDefinitionByName(this SPWebApplication webApp, string name) {
            if (webApp == null) {
                throw new ArgumentNullException("webApp", "Argument 'webApp' cannot be 'null'");
            }

            if (String.IsNullOrEmpty(name)) {
                throw new ArgumentNullException("name", "Argument 'name' cannot be 'null' or 'String.Empty'");
            }

            var retVal = from SPJobDefinition job in webApp.JobDefinitions
                         where job.Name == name
                         select job;

            return retVal.FirstOrDefault();
        }
    }
}
